import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/basic/local_info.dart';
import 'package:lcapp/data/user_data_entity.dart';

UserDataEntity userInfo=UserDataEntity();

clearUserInfo() {
  userInfo=UserDataEntity();
  AsrLocalInfo.clearLoginStatus();
}

refreshUserInfo({Function? refreshBlock})async{
  if(AsrLocalInfo.userId!=null){
    ResponseData res = await UserAPI.getUserInfo(AsrLocalInfo.userId!);
    if(res.code==200&&res.data!=null){
      userInfo = UserDataEntity().fromJson(res.data);
      userInfo.name ??= 'LC${userInfo.phone?.substring(userInfo.phone!.length-3,userInfo.phone?.length)}';
      if(userInfo.address!=null){
        userInfo.addressRegin = '${userInfo.address?.province ??''} ${userInfo.address?.city ??''} ${userInfo.address?.region ??''}' ;
        userInfo.addressDetail = userInfo.address?.detailAddress ??'';
        userInfo.region = userInfo.address?.region ??'';
        userInfo.coordinate = '${userInfo.address?.longitude??'0'},${userInfo.address?.latitude??'0'}';
      }
      ResponseData re = await UserAPI.getMinMoney();
      if(re.code==200&&re.data!=null){
        userInfo.gold = re.data['gold']??0;
        userInfo.cash = re.data['cash']??0;
      }
    }
  }
  if(refreshBlock!=null){
    refreshBlock();
  }
}